package com.example.logindemo.Controller;

import com.example.logindemo.Pojo.Msg;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//权限认证异常处理类
@ControllerAdvice
public class PermissionsException {

    @ResponseBody
    @ExceptionHandler(UnauthorizedException.class)
    public Msg unauthorizedException(Exception e){
        return Msg.error().add("msg","无权限");
    }

    @ResponseBody
    @ExceptionHandler(AuthorizationException.class)
    public Msg authorizationException(Exception e){
        return Msg.error().add("msg","权限认证失败");
    }
}
